package cn.tedu.mintmall.controller.admin;

import cn.tedu.mintmall.dto.RewardAddNewDTO;
import cn.tedu.mintmall.query.RewardQuery;
import cn.tedu.mintmall.restful.JsonPage;
import cn.tedu.mintmall.restful.JsonResult;
import cn.tedu.mintmall.service.IRewardService;
import cn.tedu.mintmall.vo.RewardVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/admin/reward", produces = "application/json; charset=utf-8")
@Api(tags = "后台-打赏管理")
@Slf4j
public class RewardController{

    @Autowired
    private IRewardService rewardService;

    // 新增打赏
    @PostMapping("/add-new")
    @ApiOperation("添加打赏")
    @ApiOperationSupport(order = 1)
    public JsonResult<Void> addNew( RewardAddNewDTO rewardAddNewDTO){
        rewardService.AddReward(rewardAddNewDTO);
        return JsonResult.ok("添加打赏成功!");

    }

    // 按打赏时间分页展示所有打赏信息
    @GetMapping("/list")
    @ApiOperation("按打赏时间分页展示所有打赏信息")
    @ApiOperationSupport(order = 2)
    public JsonResult<JsonPage<RewardVO>> findAllRewards(Integer page, Integer pageSize){

        JsonPage<RewardVO> listRewards = rewardService.findAllRewards(page, pageSize);
        return JsonResult.ok("查询所有奖赏成功!",listRewards);

    }

    // 获取打赏金额前3名的信息按金额降序
    @PostMapping("/list-by-amount")
    @ApiOperation("获取打赏金额前3名的信息按金额降序")
    @ApiOperationSupport(order = 3)
    public JsonResult<List<RewardVO>> listByAmountTopThreeRewards(){

        List<RewardVO> list = rewardService.listByAmountTopThreeRewards();
        return JsonResult.ok("获取打赏金额前3名的信息按金额降序成功!",list);

    }

    // 按条件搜索打赏信息
    @PostMapping("/list-by-conditions")
    @ApiOperation("按条件搜索打赏信息")
    @ApiOperationSupport(order = 4)
    public JsonResult<List<RewardVO>> listByCustomConditions(RewardQuery rewardQuery){

        log.info("看一下查询条件: {}", rewardQuery);
        List<RewardVO> list = rewardService.listByCustomConditions(rewardQuery);
        return JsonResult.ok("按条件搜索打赏信息成功!",list);

    }


}
